let mv = new Vue({
    el:"#app",
    data(){
        return {
            msg:"asycn 实例练手",
            result:[]
        }
    },
    created(){
        this.getData();
    },
    methods:{
        getData(){
            var show = this.getAsync();
            show().then(result => {
                console.log(result)
            }, err => {
                console.log(err)
            }).catch(err => {
                cosole.log(err)

            })
        },
        ajaxpromise(options){
            return new Promise((resovle, reject) => {
                setTimeout(() => {
                    var xhr = new XMLHttpRequest();
                    xhr.open(options.type || "get", options.url, true);
                    xhr.send(options.data || null);
                    xhr.onreadystatechange = () => {
                        if (xhr.readyState == 4) {
                            if (xhr.status == 200) {
                                var res = JSON.parse(xhr.response)
                                resovle(res)
                            } else {
                                reject(xhr)
                            }
                        }
                    }
                    
                }, 1000);
            })
        },
        getAsync(){
            var _this = this;
            return async function show() {
                let result1 = await _this.ajaxpromise({ url: "demo0.json" })
                _this.result = _this.result.concat(result1.data)
                let result2 = await _this.ajaxpromise({ url: "demo1.json" })
                _this.result = _this.result.concat(result2.data)
                let result3 = await _this.ajaxpromise({ url: "demo2.json" })
                _this.result = _this.result.concat(result3.data)
                return _this.result
            }
        }
    }

    
})

